# Contributor: Siva Mahadevan <me@svmhdvn.name>
# Contributor: Simon Frankenberger <simon-alpine@fraho.eu>
# Maintainer: Simon Frankenberger <simon-alpine@fraho.eu>
pkgname=signal-cli
pkgver=0.13.3
pkgrel=0
pkgdesc="commandline interface for libsignal-service-java"
url="https://github.com/AsamK/signal-cli"
# jdk17 only available on 64 bit archs
# cargo and rust not available on s390x and riscv64
# java-libsignal-client not available on ppc64le
arch="x86_64 aarch64"
license="GPL-3.0-or-later"
depends="java-libsignal-client"
makedepends="openjdk21-jdk"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/AsamK/signal-cli/archive/v$pkgver.tar.gz
	upgrade-gradle-fix-sigsegv-aarch64.patch
	"

build() {
	./gradlew installDist
}

check() {
	./gradlew check
}

package() {
	local buildhome="build/install/$pkgname"
	local installhome="/usr/share/java/$pkgname"

	install -dm755 "$pkgdir/$installhome/lib"
	install -m644 "$buildhome"/lib/* "$pkgdir/$installhome/lib"

	install -Dm755 "$buildhome/bin/$pkgname" "$pkgdir/$installhome/bin/$pkgname"
	install -dm755 "$pkgdir/usr/bin"
	ln -s "$installhome/bin/$pkgname" "$pkgdir/usr/bin/$pkgname"

	rm -v "$pkgdir/$installhome/lib"/libsignal-client-*.jar
	ln -sv /usr/share/java/libsignal-client/signal-client-java.jar "$pkgdir/$installhome/lib/signal-client-java.jar"
	sed -i -e 's/libsignal-client-[0-9.]\+\.jar/signal-client-java.jar/g' "$pkgdir/$installhome/bin/$pkgname"
}

sha512sums="
855c0237203e37284c41e73920920e81efae244823c9187715bd6f77474242671571bfa5adde1f2d552e3e15ddc6d1f4a9f6bdf334ad269d1f45e81bcbd36f38  signal-cli-0.13.3.tar.gz
e03849fe9fdbb2bff868e61742e5745d5cd89770b8c1aa4aa778958a7fbb291e1ee844e452b179ab59f91ce3e433a4cc7f5ffb12ce7672e7a2e6242789cd9f16  upgrade-gradle-fix-sigsegv-aarch64.patch
"
